//
//  LoginTableViewController.swift
//  amicoolView
//
//  Created by wr on 2017/5/31.
//  Copyright © 2017年 wr. All rights reserved.
//

import UIKit

class LoginTableViewController: UITableViewController {
    @IBOutlet weak var username: UITextField!
    @IBOutlet weak var password: UITextField!

    @IBAction func login(_ sender: Any) {
        if username.text?.characters.count == 0{
            pompAlert(message: "请输入用户名")
            
        }
        else if password.text?.characters.count == 0 {
            pompAlert(message: "请输入密码")
        }
        else {
            let parameters:NSDictionary = ["username":self.username.text!,"password":self.password.text!]
            //请求
            AMNetworkMngTool.shared.AMNetwork_Login(parameters, block: { (flag) in
                if flag == "1" {
                    //异步处理
                    DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()+0.5, execute: {
                        self.pompAlert(message: "登录成功")
                    })
                }
                else {
                    self.pompAlert(message: "登录失败")
                }
            })
            
        }
    }
    func pompAlert(message:String){
        let alert = UIAlertController(title: "提示", message: message, preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "确定", style: .cancel, handler: nil))
        self.present(alert, animated: true, completion: nil)
    }

    
    override func viewDidLoad() {
        super.viewDidLoad()

    }
    //处理通知
    func registerComplete(_ notification:Notification){
        let data = notification.userInfo! as NSDictionary
        let uname = data["username"]! as! String
        self.username.text = uname
    }


    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


/*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
